<?php
class FormProcessor_CustomizeSpace extends FormProcessor {
	protected $db = null;
	public $space = null;
	public function __construct($db, $userid) {
		$this->db = $db;
		parent::__construct($this->db);
		$this->space = new DatabaseObject_Space($this->db);
		$this->space->load($userid);
		
	}
	
	public function process(Zend_Controller_Request_Abstract $request) {
		$this->title = $this->sanitize($request->getPost('title'));
		if (strlen($this->title) == 0) {
			$this->addError('title', '空间名称不能为空');
		} else {
			$this->space->title = $this->title;
		}
		
		$this->subtitle = $this->sanitize($request->getPost('subtitle'));
		if (strlen($this->subtitle) == 0) {
			$this->addError('subtitle', '空间介绍不能为空');
		} else {
			$this->space->subtitle = $this->subtitle;
		}
		$menu = 0;
		for ($i = 0; $i < 8; $i++) {
			$tmp = $request->getPost('menu'.$i);
			if (strlen($tmp) != 0) {
				$menu += pow(2, (int)$tmp);
			}
			
		}
		
	    $item = 0;
        for ($i = 0; $i < 8; $i++) {
            $tmp = $request->getPost('item'.$i);
            if (strlen($tmp) != 0) {
                $item += pow(2, (int)$tmp);
            }
            
        }
        
        if (!$this->hasError()) {
        	$this->space->outmenu = $menu;
        	$this->space->outitem = $item;
        	$this->space->save();
        }
        
        return !$this->hasError();
	}
}
?>